package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionsServicesImpl implements PermissionService {
    @Autowired
    private PermissionDao permissionDao;

    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    //权限分页
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();//查询条件
        //完成分页查询，基于mybatis框架提供的分页助手插件完成
        PageHelper.startPage(currentPage, pageSize);
        Page<Permission> page = permissionDao.selectByCondition(queryString);
        return new PageResult( page.getTotal(), page.getResult());
    }

    //查询权限
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    //编辑权限
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }

    //删除
    public void delete(Integer id) {
        permissionDao.delete(id);
    }
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }
}
